package com.glsc.ngateway.opmanage.controller.other;

import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.base.domain.mysql.gateway.other.TradeAccountFurture;
import com.glsc.ngateway.common.base.domain.mysql.gateway.other.TradeAccountOwnFund;
import com.glsc.ngateway.common.base.domain.mysql.gateway.other.TradeAccountSaleFund;
import com.glsc.ngateway.common.base.domain.mysql.gateway.other.TradeAccountShareHolder;
import com.glsc.ngateway.common.base.domain.oracle.ecology.HrmdepartmentSimple;
import com.glsc.ngateway.common.base.domain.oracle.ecology.JYDYTZZB;
import com.glsc.ngateway.common.base.domain.oracle.ecology.VHrmResource;
import com.glsc.ngateway.opmanage.aspect.UserCache;
import com.glsc.ngateway.opmanage.service.UserService;
import com.glsc.ngateway.opmanage.service.other.TradeAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@RequestMapping("/tradeAccount")
@Api(value = "交易账户管理", tags = {"交易账户管理"})
public class TradeAccountController {

    private static final Logger logger = LoggerFactory.getLogger(TradeAccountController.class);
    @Autowired
    private TradeAccountService tradeAccountService;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private UserCache userCache;
    @Autowired
    private UserService userService;

    /**
     * 查询
     * @param params
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "search")
    @ApiOperation(value = "查询", notes = "查询")
    public PlatformResponse<Object> search(@RequestBody Object params) {

//
//        PlatformUserDto user = userCache.get(request);
//        String account = user.getUsername();
//        Set<String> roleNames = new HashSet<>(user.getRoles());
//        if (roleNames.contains("systemAdmin")) {
//            account = null;
//        }
//        params.setMemberAccount(account);

        Object result = tradeAccountService.search(params);
        return PlatformResponse.successData(result);
    }

    /**
     * 查询交易单元
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "getDictJYDY")
    @ApiOperation(value = "查询", notes = "查询")
    public PlatformResponse<Object> getDictJYDY() {
        List<JYDYTZZB> result = tradeAccountService.getDictJYDY();
        return PlatformResponse.successData(result);
    }

    @RequestMapping(method = RequestMethod.GET, value = "getDictHRM")
    @ApiOperation(value = "查询", notes = "查询人员")
    public PlatformResponse<Object> getDictHRM() {
        List<VHrmResource> result = tradeAccountService.getDictHRM();
        return PlatformResponse.successData(result);
    }

    @RequestMapping(method = RequestMethod.GET, value = "getDictDEPT")
    @ApiOperation(value = "查询", notes = "查询")
    public PlatformResponse<Object> getDictDEPT() {
        List<HrmdepartmentSimple> result = tradeAccountService.getDictDEPT();
        return PlatformResponse.successData(result);
    }

    @RequestMapping(method = RequestMethod.POST, value = "updateShareHolder")
    @ApiOperation(value = "修改股东", notes = "修改股东")
    public PlatformResponse<Void> updateShareHolder(@RequestBody TradeAccountShareHolder tradeAccountShareHolder) {
        tradeAccountService.updateShareHolder(tradeAccountShareHolder);
        return PlatformResponse.successMsg("修改成功");
    }

    @RequestMapping(method = RequestMethod.POST, value = "updateOwnFund")
    @ApiOperation(value = "修改自营基金", notes = "修改自营基金")
    public PlatformResponse<Void> updateOwnFund(@RequestBody TradeAccountOwnFund tradeAccountOwnFund) {
        tradeAccountService.updateOwnFund(tradeAccountOwnFund);
        return PlatformResponse.successMsg("修改成功");
    }

    @RequestMapping(method = RequestMethod.POST, value = "updateSaleFund")
    @ApiOperation(value = "修改代销基金", notes = "修改代销基金")
    public PlatformResponse<Void> updateSaleFund(@RequestBody TradeAccountSaleFund tradeAccountSaleFund) {
        tradeAccountService.updateSaleFund(tradeAccountSaleFund);
        return PlatformResponse.successMsg("修改成功");
    }

    @RequestMapping(method = RequestMethod.POST, value = "updateFurture")
    @ApiOperation(value = "修改期货", notes = "修改期货")
    public PlatformResponse<Void> updateFurture(@RequestBody TradeAccountFurture tradeAccountFurture) {
        tradeAccountService.updateFurture(tradeAccountFurture);
        return PlatformResponse.successMsg("修改成功");
    }

    @RequestMapping(method = RequestMethod.POST, value = "deleteShareHolder")
    @ApiOperation(value = "修改股东", notes = "修改股东")
    public PlatformResponse<Void> deleteShareHolder(@RequestBody TradeAccountShareHolder tradeAccountShareHolder) {
        tradeAccountService.deleteShareHolder(tradeAccountShareHolder);
        return PlatformResponse.successMsg("删除成功");
    }

    @RequestMapping(method = RequestMethod.POST, value = "deleteOwnFund")
    @ApiOperation(value = "修改自营基金", notes = "修改自营基金")
    public PlatformResponse<Void> deleteOwnFund(@RequestBody TradeAccountOwnFund tradeAccountOwnFund) {
        tradeAccountService.deleteOwnFund(tradeAccountOwnFund);
        return PlatformResponse.successMsg("删除成功");
    }

    @RequestMapping(method = RequestMethod.POST, value = "deleteSaleFund")
    @ApiOperation(value = "修改代销基金", notes = "修改代销基金")
    public PlatformResponse<Void> deleteSaleFund(@RequestBody TradeAccountSaleFund tradeAccountSaleFund) {
        tradeAccountService.deleteSaleFund(tradeAccountSaleFund);
        return PlatformResponse.successMsg("删除成功");
    }

    @RequestMapping(method = RequestMethod.POST, value = "deleteFurture")
    @ApiOperation(value = "修改期货", notes = "修改期货")
    public PlatformResponse<Void> deleteFurture(@RequestBody TradeAccountFurture tradeAccountFurture) {
        tradeAccountService.deleteFurture(tradeAccountFurture);
        return PlatformResponse.successMsg("删除成功");
    }
}